<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="项目名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目类型" prop="projectTag">
        <el-cascader
          v-model="queryParams.projectTag"
          :options="type_options"
          :props="type_props"
          clearable
        >
        </el-cascader>
      </el-form-item>
      <el-form-item label="合作方式" prop="projectCooperate">
        <!-- <el-input
          v-model="queryParams.projectCooperate"
          placeholder="请输入合作方式"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.projectCooperate"
          value-key="value"
          placeholder="请选择"
        >
          <el-option
            v-for="item in sel_costom"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="projectStatus">
        <!-- <el-input
          v-model="queryParams.projectCooperate"
          placeholder="请输入合作方式"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.projectStatus"
          value-key="value"
          placeholder="请选择"
        >
          <el-option
            v-for="item in status_costom"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['commercial:list:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['commercial:list:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['commercial:list:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['commercial:list:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="listList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="景区运营公司用户id" align="center" prop="scenicUserId" /> -->
    
      <el-table-column label="景区名称" align="center" v-if="isAdmin === false"  :key="Math.random()" prop="scenicName" />
      <el-table-column label="景区名称" align="center" v-if="isAdmin === true"  :key="Math.random()" prop="scenicName2" />
 
      <el-table-column label="运营公司" align="center" prop="companyName" />
      <el-table-column label="项目地址" align="center" prop="projectAddress" />
      <el-table-column label="联系人" align="center" prop="linkName" />
      <el-table-column label="联系电话" align="center" prop="linkTel" />
      <el-table-column label="项目名称" align="center" prop="productName" />
      <el-table-column
        label="项目类型"
        align="center"
        prop="projectTag"
        :formatter="tagFormat"
      />
      <el-table-column label="合作方式" align="center" prop="projectCooperate">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.commercial_coop_type"
            :value="
              scope.row.projectCooperate
                ? scope.row.projectCooperate.split(',')
                : []
            "
          />
        </template>
      </el-table-column>
      <el-table-column
        label="项目截止日期"
        align="center"
        prop="projectDeadline"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.projectDeadline, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="宣传内容" align="center" prop="propagateContent" /> -->
      <el-table-column label="是否推荐" align="center" prop="isRecommend">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.isRecommend"
          />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="projectStatus">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.commercial_case_status"
            :value="scope.row.projectStatus"
          />
        </template>
      </el-table-column>
      <el-table-column label="图片" align="center" prop="projectPics">
        <template slot-scope="scope">
          <el-popover placement="top-start" trigger="click">
            <a :href="scope.row.projectPics" target="_blank" title="查看图片">
              <img
                :src="scope.row.projectPics"
                style="width: 500px; height: 400px"
              />
            </a>
            <img
              slot="reference"
              :src="scope.row.projectPics"
              style="width: 50px; height: 50px; cursor: pointer"
            />
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        label="发布时间"
        align="center"
        prop="publishTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publishTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="最后修改时间"
        align="center"
        prop="modifyTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['commercial:list:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['commercial:list:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList2"
    />

    <!-- 添加或修改招商列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="选择景区" prop="sceneBaseId">
          <!-- <el-input v-model="form.scenicUserId" placeholder="请输入景区运营公司用户id" /> -->
          <template>
            <el-select
              v-model="form.sceneBaseId2"
              value-key="id"
              @change="changeSceneBase"
              placeholder="请选择景区"
            >
              <el-option
                v-for="item in sceneBaseList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </template>
        </el-form-item>

        <el-form-item label="选择景区供应公司" prop="scenicUserId">
          <!-- <el-input v-model="form.scenicUserId" placeholder="请输入景区运营公司用户id" /> -->
          <template>
            <el-select
              v-model="form.scenicUserId"
              value-key="id"
              @change="changeSceneMember"
              placeholder="请选择景区公司"
            >
              <el-option
                v-for="item in scenememberList"
                :key="item.id"
                :label="item.companyName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </template>
        </el-form-item>

        <el-form-item label="项目地址" prop="projectAddress">
          <el-input
            v-model="form.projectAddress"
            placeholder="请输入项目地址"
          />
        </el-form-item>
        <el-form-item label="联系人" prop="linkName">
          <el-input
            v-model="form.linkName"
            placeholder="请输入联系人"
          />
        </el-form-item>
        <el-form-item label="联系电话" prop="linkTel">
          <el-input
            v-model="form.linkTel"
            placeholder="请输入联系电话"
          />
        </el-form-item>
        <el-form-item label="项目名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目类型" prop="projectTag">
          <!-- <el-input v-model="form.projectTag" placeholder="请输入项目类型" /> -->
          <div class="block">
            <el-cascader
              v-model="form.projectTag"
              :options="type_options"
              :props="type_props"
              clearable
            >
            </el-cascader>
          </div>
        </el-form-item>
        <el-form-item label="合作方式" prop="checkBoxSel">
          <!-- <el-input v-model="form.projectCooperate" placeholder="请输入合作方式" /> -->
          <el-checkbox-group v-model="checkBoxSel" @change="checkChange">
            <el-checkbox
              v-for="item in sel_costom_o"
              :key="item.value"
              :label="item.value"
            >
              {{ item.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="项目截止日期" prop="projectDeadline">
          <el-date-picker
            clearable
            v-model="form.projectDeadline"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择项目截止日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目描述" prop="projectDescription">
          <el-input
            type="textarea"
            :rows="3"
            v-model="form.projectDescription"
            placeholder="请输入项目描述"
            maxlength="50000"
            show-word-limit
          />
        </el-form-item>
        <!-- <el-form-item label="宣传内容" prop="propagateContent">
          <editor v-model="form.propagateContent" :min-height="192"/>
        </el-form-item> -->
        <el-form-item label="是否推荐" prop="isRecommend">
          <!-- <el-input v-model="form.isRecommend" placeholder="请输入是否上架招商" /> -->
          <el-select v-model="form.isRecommend" placeholder="请选择">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.value"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否上架" prop="projectStatus">
          <!-- <el-input v-model="form.isRecommend" placeholder="请输入是否上架招商" /> -->
          <el-select v-model="form.projectStatus" placeholder="请选择">
            <el-option
              v-for="dict in dict.type.commercial_case_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="图片" prop="projectPics">
          <!-- <el-input v-model="form.projectPics" type="textarea" placeholder="请输入内容" /> -->
          <el-upload
            class="upload-demo"
            :limit="1"
            :action="uploadFileUrl"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            :on-success="handleUploadSuccess"
            :data="updata"
            :headers="headers"
            :file-list="fileList"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">不超过1Mb</div>
          </el-upload>
        </el-form-item>

        <!-- <el-form-item label="发布时间" prop="publishTime">
          <el-date-picker clearable
            v-model="form.publishTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发布时间">
          </el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="最后修改时间" prop="modifyTime">
          <el-date-picker clearable
            v-model="form.modifyTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择最后修改时间">
          </el-date-picker>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listList,
  getList,
  delList,
  addList,
  addListbyAdmin,
  updateList,
} from "@/api/commercial/list";
import { listAllType } from "@/api/supplier/case";
import { listScenemember } from "@/api/scene/scenemember";
import { listScenebase } from "@/api/scenebase/scenebase";
import { getToken } from "@/utils/auth";
import { getScenemember } from "@/api/scene/scenemember";
import { getUserProfile } from "@/api/system/user";

import axios from "axios";
export default {
  name: "List",
  dicts: ["commercial_coop_type", "sys_yes_no", "commercial_case_status"],

  data() {
    return {
      sel_costom_o: [
        {
          value: 1,
          label: "分成",
        },
        {
          value: 2,
          label: "租赁",
        },
        {
          value: 3,
          label: "采购",
        },
      ],
      sel_costom: [
        {
          value: 1,
          label: "分成",
        },
        {
          value: 2,
          label: "租赁",
        },
        {
          value: 3,
          label: "采购",
        },
        {
          value: 9,
          label: "非采购",
        },
      ],
      status_costom: [
        {
          value: 0,
          label: "未上架",
        },
        {
          value: 1,
          label: "已上架",
        },
        {
          value: 2,
          label: "已下架",
        },
      ],
      type_props: {
        multiple: true,
        value: "id",
        label: "typeName",
        children: "sub_type_list",
      },
      type_options: [],
      hashmap_main: null,
      hashmap_sub: null,
      isAdmin: false,
      fileList: [],
      baseUrl: process.env.VUE_APP_BASE_API,
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/uploadFile", // 上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      uploadObjectUrl: "", // 纯前端预览地址-upload
      uploadOnlineUrl: "", // 后端返回的上传地址-upload
      updata: { "strPath": "pics" },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招商列表表格数据
      listList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 景区注册公司表格数据
      scenememberList: [],
      sceneBaseList: [],
      sceneBaseName: null,
      sceneBaseId: null,
      checkBoxSel: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scenicName: null,
        companyName: null,
        projectAddress: null,
        productName: null,
        projectTag: null, //JSON.stringify([[2,0]]),
        projectCooperate: [],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sceneBaseId: [
          { required: true, message: "景区不能为空", trigger: "change" },
        ],
        scenicUserId: [
          {
            required: true,
            message: "景区运营公司用户不能为空",
            trigger: "change",
          },
        ],
        scenicName: [
          { required: true, message: "景区名称不能为空", trigger: "change" },
        ],
        productName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" },
        ],
        // checkBoxSel: [
        //   { type: 'array', required: true, message: '请至少选择一个合作方式', trigger: 'change' }
        //   ],
        propagateContent: [
          { required: true, message: "宣传内容不能为空", trigger: "blur" },
        ],
        projectDescription: [
          { required: true, message: "项目描述不能为空", trigger: "blur" },
        ],
        projectPics: [
          { required: true, message: "景区图片不能为空", trigger: "change" },
        ],
        isRecommend: [
          { required: true, message: "是否推荐不能为空", trigger: "blur" },
        ],
        projectStatus: [
          { required: true, message: "是否上架不能为空", trigger: "blur" },
        ],
      },
    };
  },

  async created() {
    // this.handle_sel_costom();

    await this.getTypeList();
    await this.getSceneBaseList();
    await this.getList2();
    await this.getUserInfo();
    //this.createHashMap();
  },

  methods: {
    getUserInfo() {
       getUserProfile().then(response => {
        this.isAdmin = response.data.admin;
      });
    },
    isArray(o) {
      return Object.prototype.toString.call(o) == "[object Array]";
    },

    checkChange(val) {
      console.log("val", val);
    },

    tagFormat(row, column, value) {
      //console.log('row', row);
      let val = JSON.parse(value);
      let that = this;
      //console.log(val.length, val);
      if (val == null || !(val instanceof Array)) return "";
      if (that.hashmap_main == null) return "";
      // let t =  val.map(t=>
      //   (that.hashmap_main[(t[0]-0)] + '-' + that.hashmap_sub[(t[1]-0)] )
      // )
      let t = "";
      for (var item of val) {
        // [3,13]是一个item, [3,16]是另一个item
        var s1 = item[0] - 0;
        var s2 = item[1] - 0;
        //console.log(that.hashmap_main[s1]);
        t = t + that.hashmap_main[s1] + "-" + that.hashmap_sub[s2] + ",";
      }

      return t;
    },
    handle_sel_costom() {
      // var newItem1 = {}
      // newItem1.value = 1
      // newItem1.label = '分成'
      // this.sel_costom.push(newItem1)
      // var newItem2 = {}
      // newItem2.value = 2
      // newItem2.label = '租赁'
      // this.sel_costom.push(newItem2)
      // var newItem3 = {}
      // newItem3.value = 3
      // newItem3.label = '采购'
      // this.sel_costom.push(newItem3)
      // var newItem4 = {}
      // newItem4.value = 9
      // newItem4.label = '非采购'
      // this.sel_costom.push(newItem4)
    },

    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    handleUploadSuccess(res, file) {
      this.$refs.form.clearValidate("projectPics");

      // this.imageObjectUrl = URL.createObjectURL(file.raw);
      //this.uploadOnlineUrl = res.path;
      //

      console.log(res.urls);
      this.form.projectPics = res.data.url;
    },
    changeSceneBase(val) {
      console.log(val);
      this.sceneBaseId = val.id;
      for(var i of this.sceneBaseList){
        if(i.id == val){
          this.form.scenicName = i.name
          console.log(i.name)
          break
        }
      }
    
      this.getSceneComList(val.id);
    },

    changeSceneMember(val) {
      let that = this;
      console.log(val);
      //通过val读取sceneUser的信息
      getScenemember(val).then((rep) => {
        // that.form.sceneBaseId  = rep.data.sceneBaseId - 0;
        that.form.linkName = rep.data.linkName;
        that.form.linkTel = rep.data.linkTel;
        that.form.companyName = rep.data.companyName;
      });
      // this.form.link
      //this.form.scenicUserId = val.id
      // this.form.linkName = val.linkName
      //this.form.linkTel = val.linkTel
      // this.sceneBaseId = val.id
      // this.getSceneComList(val.id)
    },

    /** 查询招商列表列表 */
    getList() {
      this.loading = true;
      axios({
        method: "get",
        headers: { Authorization: "Bearer " + getToken() },
        url: process.env.VUE_APP_BASE_API + "/commercial/list/list",
        params: this.queryParams,
      }).then((response) => {
        console.log(response);
        this.listList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 查询招商列表列表用于加类型查询 */
    getList2() {
      this.loading = true;
      let that = this;
      axios({
        method: "post",
        headers: { Authorization: "Bearer " + getToken() },
        url: process.env.VUE_APP_BASE_API + "/commercial/list/list2Admin?pageNum="+this.queryParams.pageNum+'&pageSize='+this.queryParams.pageSize,
        data: this.queryParams,
      }).then((response) => {
        console.log(response);
        that.listList = response.data.rows;
        that.total = response.data.total;
        that.loading = false;
      });
    },

    // 获取景区基础列表用于下拉选择
    getSceneBaseList() {
      listScenebase({
        pageNum: 1,
        pageSize: 10000,
      }).then((response) => {
        this.sceneBaseList = response.rows;
      });
    },

    // 获取景区运营公司列表用于下拉选择 k-v对应,val为景区基础baseid
    // wangjia 20220727 对于admin角色，可以自由选择公司，这里显示全部公司
    getSceneComList(sceneBaseId) {
      if(this.isAdmin == false) {
        listScenemember({
        pageNum: 1,
        pageSize: 1000,
        sceneBaseId: sceneBaseId,
          }).then((response) => {
            this.scenememberList = response.rows;
          });
      }else {
        listScenemember({
        pageNum: 1,
        pageSize: 1000,
          }).then((response) => {
            this.scenememberList = response.rows;
          });
      }
      
    },

    getTypeList() {
      let that = this;
      listAllType()
        .then((response) => {
          that.type_options = response.data;
          console.log(that.type_options);
        })
        .then(() => {
          that.hashmap_main = {};
          that.hashmap_sub = {};

          for (var i of that.type_options) {
            that.hashmap_main[i.id] = i.typeName;
            for (var j of i.sub_type_list) {
              that.hashmap_sub[j.id] = j.typeName;
            }
          }
          // console.log(that.hashmap_main)
          // console.log(that.hashmap_sub)
        });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        scenicUserId: null,
        scenicName: null,
        companyName: null,
        projectAddress: null,
        linkName: null,
        linkTel: null,
        productName: null,
        projectTag: null,
        projectCooperate: [],
        projectDeadline: null,
        projectDescription: null,
        propagateContent: null,
        isRecommend: null,
        projectStatus: "0",
        projectPics: null,
        publishTime: null,
        modifyTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.projectTag != null)
        this.queryParams.projectTag = JSON.stringify(
          this.queryParams.projectTag
        );
      console.log("搜索按钮操作:" + JSON.stringify(this.queryParams));
      this.getList2();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加招商列表";
    },
    /** 修改按钮操作 */
    /**
     * wangjia 20220727 对于admin来说由于是自由匹配景区基础和景区公司，这里对admin角色进行
     * 特殊处理，从库中读取的是什么数据就是显示什么数据
    */
    handleUpdate(row) {
      this.reset();
      let that = this;
      console.log("ssss", JSON.parse(JSON.stringify(that.scenememberList)));
      const id = row.id || this.ids;
      getList(id).then((response) => {
        that.form = response.data;
        let temp = that.form.projectCooperate.split(",");
        that.checkBoxSel = temp.map((i) => i - 0);
        //console.log(eval(that.form.projectTag))
        that.form.projectTag = eval(that.form.projectTag);
        //that.checkBoxSel = ;
        // that.form.projectCooperate = this.form.projectCooperate.split(","); // 存入数据库的字段是一个字符串，不是数组。点击修改时切换成数组
        // console.log(that.form.projectCooperate)
        let userid = that.form.scenicUserId;
        // 景区运营公司的选择
        if(this.isAdmin == false) {
          getScenemember(userid).then((rep) => {
            that.form.sceneBaseId = rep.data.sceneBaseId - 0;
            that.getSceneComList(that.form.sceneBaseId);
           
          });
        } else { // 显示add时选择的自由景区基础数据
         for(var ii of that.sceneBaseList) {
           if(ii.name == that.form.scenicName2){
            that.form.sceneBaseId = ii.id
            that.getSceneComList(that.form.sceneBaseId);
            break;
           }
         }
        }
       
        that.open = true;
        that.title = "修改招商列表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      let that = this;
      // console.log(this.sel_costom);
      if (!this.form.projectTag) {
        this.$message.error("错了哦，请选择项目类型");
        return;
      }
      if (!this.form.projectCooperate) {
        this.$message.error("错了哦，请选择合作方式");
        return;
      }

      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (
            that.form.projectTag != null &&
            typeof that.form.projectTag != "string"
          )
            that.form.projectTag = JSON.stringify(that.form.projectTag);
          that.form.projectCooperate = that.checkBoxSel.join(",");
          
          that.form.projectMsg = that.tagFormat(null, null, that.form.projectTag)
          if (that.form.id != null) {
            updateList(that.form).then((response) => {
              that.$modal.msgSuccess("修改成功");
              that.open = false;
              that.getList();
            });
          } else {
            addListbyAdmin(that.form).then((response) => {
              that.$modal.msgSuccess("新增成功");
              that.open = false;
              that.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除招商列表编号为"' + ids + '"的数据项？')
        .then(function () {
          return delList(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "commercial/list/export",
        {
          ...this.queryParams,
        },
        `list_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
